import {
    defaultEquals
} from "./util";
import {
    Node
} from "./models/linked-list-models";
export default class LinkedList {
    constructor(equalsFn = defaultEquals) {
        this.count = 0;
        this.head = null;
        this.equalsFn = equalsFn;
    }
    push(element) {
        const node = new Node(element);
        if (this.head === null) {
            this.head = node;
        } else {
            let curNode = this.head;
            while (curNode.next !== null) {
                curNode = curNode.next;
            }
            curNode.next = node;
        }
        this.count++;
    }
    removeAt(index) {
        if (index >= 0 && index < this.count) {
            let preNode;
            if (index == 0) {
                preNode = this.head;
                this.head = this.head.next;
            } else {
                let num = 0;
                let curNode = this.head;
                while (num < (index - 1)) {
                    curNode = curNode.next;
                }
                preNode = curNode.next;
                curNode.next = curNode.next.next;
            }
            this.count--;
            return preNode.element;
        }
        return undefined;
    }
}